//
//  AppDelegate.m
//  cocos2dappfwk
//
//  Created by Development on 21/07/2010.
//  Copyright Lowrie Associates Ltd 2010. All rights reserved.
//

#import "AppDelegate.h"
#import "cocos2d.h"
#import "LoaderScene.h"

@implementation AppDelegate

@synthesize window, overlay;

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
	window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];	

	if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )								
		[CCDirector setDirectorType:kCCDirectorTypeNSTimer];									

	CCDirector *director = [CCDirector sharedDirector];										
	[director setDeviceOrientation:kCCDeviceOrientationPortrait];								
	[director setDisplayFPS:YES];																
	[director setAnimationInterval:1.0/60];													
	EAGLView *glView = [EAGLView viewWithFrame:[[UIScreen mainScreen] bounds] pixelFormat:kEAGLColorFormatRGBA8 depthFormat:0 preserveBackbuffer:NO];											
	[director setOpenGLView:glView];														

	[glView setMultipleTouchEnabled:YES];
	glView.opaque = NO;
	glClearColor(0.0f,0.0f,0.0f,0.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	overlay = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
	overlay.opaque = YES;
	overlay.backgroundColor = [UIColor blackColor];
	[overlay addSubview:glView];

	[window addSubview:overlay];																
	[window makeKeyAndVisible];																	
	
	[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
	[director runWithScene: [LoaderScene scene]];	
}


- (void)applicationWillResignActive:(UIApplication *)application {
	[[CCDirector sharedDirector] pause];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
	[[CCDirector sharedDirector] resume];
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
	[[CCDirector sharedDirector] purgeCachedData];
}

- (void)applicationWillTerminate:(UIApplication *)application {
	[[CCDirector sharedDirector] end];
}

- (void)applicationSignificantTimeChange:(UIApplication *)application {
	[[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
}

- (void)dealloc {
	[[CCDirector sharedDirector] release];
	[window release];
	[super dealloc];
}

@end
